package com.tc.gateway.device.remote;

import java.util.ArrayList;
import java.util.Collection;

import com.byq.mm.abstractx.cluster.server.executor.Executor;
import com.byq.mm.abstractx.device.Cluster;
import com.byq.mm.application.cluster.provider.LevelControlProvider;
import com.byq.mm.application.cluster.provider.ObdProvider;
import com.byq.mm.application.cluster.provider.OnoffProvider;
import com.byq.mm.application.cluster.provider.TunnelProvider;
import com.byq.mm.application.cluster.server.LevelControlServer;
import com.byq.mm.application.cluster.server.ObdServer;
import com.byq.mm.application.cluster.server.OnoffServer;
import com.byq.mm.application.cluster.server.TunnelServer;
import com.byq.mm.application.cluster.server.executor.LevelControlExecutor;
import com.byq.mm.application.cluster.server.executor.ObdExecutor;
import com.byq.mm.application.cluster.server.executor.OnoffExecutor;
import com.byq.mm.foundation.cluster.datatype.ByteArrayValue;
import com.byq.mm.foundation.cluster.datatype.DoubleValue;
import com.byq.mm.foundation.cluster.server.BasicClusterServer;
import com.tc.gateway.device.listener.OnoffLevelListener;
import com.tc.gateway.device.type.OnoffLevelDevice;

public class OnoffLevelController extends RemoteController<OnoffLevelDevice> implements OnoffLevelListener{
	
	public OnoffLevelController(OnoffLevelDevice device) {
		super(device);
		// TODO Auto-generated constructor stub
	}

	public void onChange(boolean value) {
		onoffserver.onChange(value);
		
	}
	OnoffServer onoffserver;
	LevelControlServer levelserver;
	public Executor getExecutor(BasicClusterServer server) {
		if(server instanceof OnoffServer){
		onoffserver = (OnoffServer)server;
		onoffserver.onChange(device.getOnOff());
		return new OnoffExecutor(){

			public void off() {
				// TODO Auto-generated method stub
				
			}

			public void on() {
				// TODO Auto-generated method stub
				
			}

			public void toggle() {
				device.toggle();
				
			}};
		}
		if(server instanceof LevelControlServer){
			levelserver = (LevelControlServer)server;
			levelserver.onValueChange(new DoubleValue(device.getLevel()));
			return new LevelControlExecutor(){

				public void level(double level) {
					levelserver.onValueChange(new DoubleValue(level));
					
				}};
		}
		return null;
	}

	@Override
	protected Collection<Cluster> getSupportedClusters() {
		Collection<Cluster> rst = new ArrayList<Cluster>();
		Cluster c = new Cluster();
		c.setId(OnoffProvider.Define.CLUSTER_NAME);
		rst.add(c);
		
		
		 c = new Cluster();
		c.setId(LevelControlProvider.Define.CLUSTER_NAME);
		rst.add(c);
		return rst;
	}
	public void onLevel(double level) {
		// TODO Auto-generated method stub
		
	}

	public void range(double min, double max) {
		// TODO Auto-generated method stub
		
	}
}